<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<%Call CheckAdmin2()%>
<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>
<style type="text/css" media="all">

</style>
<script language="javascript">
var TempArr=[];//存贮option

function Init(){
var SelectObj=document.eventadd.elements["demo"]
/*先将数据存入数组*/
with(SelectObj)
	for(i=0;i<length;i++)TempArr[i]=[options[i].text,options[i].value]
}

function SelectTip(flag){
var TxtObj=document.eventadd.elements["tempinput"]
var SelectObj=document.getElementById("demo")
var Arr=[]
with(SelectObj){
	var SelectHTML=innerHTML.match(/<[^>]*>/)[0]
	for(i=0;i<TempArr.length;i++)
	if(TempArr[i][0].indexOf(TxtObj.value)>-1||flag)//若找到以txt的内容开头的，添option。若flag为true,对下拉框初始化
	Arr[Arr.length]="<option value='"+TempArr[i][1]+"'>"+TempArr[i][0]+"</option>"
	innerHTML=SelectHTML+Arr.join()+"</SELECT>"
}
}
</script>

</head>

<body onload="Init()">

<div class="header">
<!--#include file="menu.asp"-->
</div>
<div class="main">
			<%
				dim sdate

			select case Request("action")
			case "del"
				Call eventdel(Request("id"))
				Call getCueInfo("调分记录"&Request("id")&"已被删除")
			case "end"
				Call eventEnd(Request("id"))
				Call getCueInfo("调分已归档")
			case "ends"
				Call eventEnds(Request("count"))
				Call getCueInfo("约20条调分记录已被归档,可以点击相应角色查看")
			end select
			%>
			
	<div class="sideframe">
			<%
			select case Request("action")
			case "add"
				Call SE_ADD()
			case "edit"
				Call SpecEvent_editFrom(Request("id"))
			case else
				Call SpecEvent_addFrom()
			end select
			%>
	</div>
	<div class="rightframe">
		<%
				call SpecEvent_list("")
		%>
	</div>
</div>
<div id="footer"><!--#include file="footer.asp"--></div>
<script language="javascript">
	$("textarea[name=object]").focus(
		function () {
			$("div.playerselectlayer").show()
		}
	);
	$("div.playerselectlayer .close").click(
		function () {
			$("div.playerselectlayer").hide()
		}
	);
	$("input[name=event_dkp]").focus(
		function () {
			$("div.playerselectlayer").hide()
		}
	);

</script>
</body>
</html>
<%
Function playerselect(target)
			playerselect= playerselect & "<input type='text' name='tempinput' value='' size='16' onkeyup='SelectTip(0)'/><br><span id=""demo""><select name='demo' style='width:120px' size='10' onchange=""object.value=object.value+'|'+options[selectedIndex].text;"">"
			Sql="Select * from player order by player_name"
			rs2.open sql,conn,1,1
				for i=1 to rs2.recordcount
					playerselect= playerselect & "<option value='"&rs2("player_name")&"'>"&rs2("player_name")&"</option>"
				rs2.movenext
				next
			rs2.close
			playerselect= playerselect & "</select></span>"
End Function

SUB SpecEvent_addFrom()
	sdate=now()
	'特殊事件添加表单
	'马甲替身, 仓库购买, 纪律奖惩, DKP转让, 其它
			Response.write "<form name='eventadd' action='admin_eventadd.asp?action=add' method='post'>"
			Response.write "<table class='short outframe interlace'>"
			Response.write "<tr><th>新建调分</th></tr>"
			Response.write "<tr><td><div class='playerselectlayer outframe'><a href='javascript:void(0)' class='close'>X</a>"&playerselect(1)&"</div><textarea name='object' rows='5' cols='31'></textarea></td></tr>"
			Response.write "<tr><td>分数 "&formselect("raid_class","id","class_name"," ")&" <input type='text' name='event_dkp' value='' size='6'/></td></tr>"
			Response.write "<tr><td>原因 "&speceventclass("")&" <input type='' name='object2' value=''  size='10'/></td></tr>"
			Response.write "<tr><td>日期 <input type='text' name='event_date' size='14' value='"&Date()&"' /><input type='hidden' name='event_time' value='' /></td></tr>"
			Response.write "<tr><td><input type='submit' value='确定'/><input type='hidden' name='postid' value='0' /></td></tr>"
			Response.write "</table>"
			Response.write "</form>"	
end sub


SUB SpecEvent_editFrom(id)
	if not isNumeric(id) then exit sub
	sdate=now()
	'特殊事件添加表单
	'马甲替身, 仓库购买, 纪律奖惩, DKP转让, 其它
	sql="select * from raid_event where id="&id
	rs.open sql,conn,1,1
		if rs.bof or rs.eof then
		else
			Response.write "<form name='eventadd' action='admin_eventadd.asp?action=edit' method='post'>"
			Response.write "<table class='short outframe interlace'>"
			Response.write "<tr><th>修改已有调分</th></tr>"
			Response.write "<tr><td><div class='playerselectlayer outframe'><a href='javascript:void(0)' class='close'>X</a>"&playerselect(1)&"</div><textarea name='object' rows='5' cols='31'>"&rs("event_object")&"</textarea></td></tr>"
			Response.write "<tr><td>分数 "&formselect("raid_class","id","class_name",Cstr(rs("raid_class")))&" <input type='text' name='event_dkp' value='"&rs("event_dkp")&"' size='6'/></td></tr>"
			Response.write "<tr><td>原因 "&speceventclass(rs("event_class"))&" <input type='' name='object2' value='"&rs("event_object2")&"'  size='10'/></td></tr>"
			Response.write "<tr><td>日期 <input type='text' name='event_date' size='14' value='"&rs("event_time")&"' /><input type='hidden' name='event_time' value='' /></td></tr>"
			Response.write " <td><input type='submit' value='编辑'/> <a href='admin_SpecEvent.asp'>取消</a><input type='hidden' name='postid' value='"&rs("id")&"' /><input type='hidden' name='rid' value='0' /></td></tr>"
			Response.write "</table>"
			Response.write "</form>"
		end if
	rs.close
end sub

SUB SpecEvent_list(sstr)
	'特殊事件列表
	Dim sctstr
	Select Case sstr
	Case ""
		sctstr=""
	Case ""
		sctstr=""
	Case ""
		sctstr=""
	Case ""
		sctstr=""
	Case ""
		sctstr=""
	Case else
		sctstr=""
	End Select

	sql="select * from raid_event where event_raidid=0 "&sctstr&" order by id desc ,event_time desc"
	rs.open sql,conn,1,1

	Response.write "<table class='interlace outframe hasfocus'>"
	Response.write "<tr><th colspan='7'><div class='title'><img src='images/icon/note1.jpg' width='64' height='64' border=0 alt=''>调分事件列表 "&rs.recordcount&"条</div><div class='filter'><a href='?action=ends&count=20' class='abtn3'>归档最早的20条</a></div></th></tr>"
	Response.write "<tr class='coltitle'><td>时间</td><td>类型</td><td>事件人物 </td><td>解释</td><td>DKP</td><td>分类</td><td>操作</td></tr>"

	if rs.bof or rs.eof then
		Response.write "<tr><td colspan='7'>None.</td></tr>"
	else
		for i=1 to rs.recordcount
		Response.write "<tr><td>"&rs("event_time")&"</td><td>"&rs("event_class")&"</td><td>"&rs("event_object")&"</td><td>"&rs("event_object2")&"</td><td>"&rs("event_dkp")&"</td><td>"&raidclassText(rs("raid_class"))&"</td><td><a href='?action=edit&id="&rs("id")&"' class='abtn'>编辑</a> <a href='?action=del&id="&rs("id")&"' class='abtn4'>删除</a> "
		if Session(ULVL)<2 then Response.write "<a href='?action=end&id="&rs("id")&"' class='abtn3'>归档</a>"
		Response.write "</td></tr>"
		rs.movenext
		next
	end if
	rs.close
	Response.write "</table>"
end sub


SUB SE_ADD()
	'特殊事件添加SQL
end sub

sub eventdel(id)
	if not IsNumeric(request("postid")) then exit sub
	sql="delete 1 from raid_event where id="&id
	conn.execute(sql)
	'Response.redirect Url
end sub



Sub eventEnd(id)
	Dim sid
	Dim ename , etime , eDKP , eNote , eDKPClass , eClass
	sid=id
		'读事件
		sql="select * from raid_event where id="&sid&" order by event_time desc"
		rs.open sql,conn,1,1
		if rs.bof or rs.eof then
			rs.close
			Response.write "事件ID错误"
			Exit Sub
		else
			ename = rs("event_object")
			etime = rs("event_time")
			eDKP = rs("event_dkp")
			eNote = rs("event_object2")
			eDKPClass = rs("raid_class")
			eClass = rs("event_class")
			rs.close

			if Instr(ename,"|") then
				ename=Mid(ename,2,Len(ename)-2)
				response.write ename
				ename=split(ename,"|")
			else
				ename=Array(ename)
			end if

			'写
			for i = 0 to Ubound(ename)
				sql="select * from player where player_name='"&ename(i)&"'"
				rs.open sql,conn,1,3
				if rs.bof or rs.eof then
					Response.write "找不到成员:"&ename(i)&" "
				else
					Conn.execute("update player_dkp set player_dkp=player_dkp+"&eDKP&" , player_Basedkp=player_Basedkp+"&eDKP&" where player_name='"&ename(i)&"' and raid_class="&eDKPClass)
					rs("player_log")=rs("player_log")&"<li>"&etime&" 分类:"&raidclassText(eDKPClass)&" 调分:"&eDKP&" 事由:"&eNote&"</li>"
					rs.update
				end if
				rs.close
			next

			'删
			eventdel(sid)
			'Response.redirect Url
		end if
End Sub




Sub eventEnds(count)
	Dim eid , ename , etime , eDKP , eNote , eDKPClass , eClass
		'读事件
	for k = 1 to count
		sql="select * from raid_event where event_raidid=0 order by event_time"
		rs.open sql,conn,1,1
		if rs.bof or rs.eof Then
			rs.close
			Response.write "没有记录可被归档"
			Exit Sub
		else
			eid = rs("id")
			ename = rs("event_object")
			etime = rs("event_time")
			eDKP = rs("event_dkp")
			eNote = rs("event_object2")
			eDKPClass = rs("raid_class")
			eClass = rs("event_class")
			rs.close

			if Instr(ename,"|") then
				ename=Mid(ename,2,Len(ename)-2)
				response.write ename
				ename=split(ename,"|")
			else
				ename=Array(ename)
			end if

			'写
			for i = 0 to Ubound(ename)
				sql="select * from player where player_name='"&ename(i)&"'"
				rs.open sql,conn,1,3
				if rs.bof or rs.eof then
					Response.write "找不到成员:"&ename(i)&" "
				else
					Conn.execute("update player_dkp set player_dkp=player_dkp+"&eDKP&" , player_Basedkp=player_Basedkp+"&eDKP&" where player_name='"&ename(i)&"' and raid_class="&eDKPClass)
					rs("player_log")=rs("player_log")&"<li>"&etime&" 分类:"&raidclassText(eDKPClass)&" 调分:"&eDKP&" 事由:"&eNote&"</li>"
					rs.update
				end if
				rs.close
			next
			'删
			eventdel(int(eid))
		end if
	next
	'Response.redirect Url
End Sub
%>